//hdu2255
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 301;
const int inf = 1<<25;
int map[maxn][maxn];
int slack[maxn];
int linked[maxn];
int label_x[maxn], label_y[maxn];
bool visited_x[maxn], visited_y[maxn];
int nx, ny;

void init_label()
{
	fill(label_x, label_x + nx, -inf);
	fill(label_y, label_y + ny, 0);
	for (int i = 0; i < nx; i++)
		for (int j = 0; j < ny; j++)
			if (map[i][j] > label_x[i]) label_x[i] = map[i][j];
}

bool hungarian_dfs(int u)
{
	visited_x[u] = true;
	for (int i = 0; i < ny; i++) {
		if (visited_y[i]) continue;
		int tmp = label_x[u] + label_y[i] - map[u][i];
		if (tmp == 0) {
			visited_y[i] = true;
			if (linked[i] == -1 || hungarian_dfs(linked[i])) {
				linked[i] = u;
				return true;
			}
		} else
			if (slack[i] > tmp) slack[i] = tmp;
	}
	return false;
}

int kuhn_munkres()
{
	init_label();
	fill(linked, linked + ny, -1);
	for (int i = 0; i < nx; i++) {
		fill(slack, slack + ny, inf);
		while (true) {
			fill(visited_x, visited_x + nx, false);
			fill(visited_y, visited_y + ny, false);
			if (hungarian_dfs(i)) break;
			int d = inf;
			for (int i = 0; i < ny; i++)
				if (!visited_y[i] && d > slack[i]) d = slack[i];
			for (int i = 0; i < nx; i++)
				if (visited_x[i]) label_x[i] -= d;
			for (int i = 0; i < ny; i++)
				if (visited_y[i]) label_y[i] += d;
				else				slack[i] -= d;
		}
	}
	int max_value = 0;
	for (int i = 0; i < ny; i++)
		if (linked[i] != -1) max_value += map[linked[i]][i];
	return max_value;
}

int main()
{
	ios::sync_with_stdio(false);
	while (cin >> nx) {
		ny = nx;
		for (int i = 0; i < nx; i++)
			for (int j = 0; j < ny; j++) cin >> map[i][j];

		cout << kuhn_munkres() << endl;
	}
}

